const mutations = {
    addCart(state, info) {
        // console.log(info);
        // console.log(info.id);

        console.log(state)
            // 1.查看是否添加过
        const oldInfo = state.cartList.find(item => item.id === info.id)

        // // 2.+1或者新添加
        if (oldInfo) {
            oldInfo.count += 1
        } else {
            info.count = 1
            info.checked = true
            state.cartList.push(info)
        };

    },
    addCart2(state, info) {
        console.log(state);

        // 1.查看是否添加过
        const oldInfo = state.cartList2.find(item => item.id === info.id)

        // 2.+1或者新添加
        if (oldInfo) {
            oldInfo.count += 1
        } else {
            info.count = 1
            info.checked = true
            state.cartList2.push(info)
        };
    },
    addCart3(state) {

        let arr = state.cartList2;
        // console.log(state.cartList)
        // console.log(state.cartList2)
        for (let i = 0; i < state.cartList.length; i++) {
            for (let j = 0; j < state.cartList2.length; j++) {
                if (state.cartList[i].id === state.cartList2[j].id) {
                    state.cartList[i].count += 1;
                    // console.log(state.cartList[i].count);
                    arr.splice(j, 1);
                } else {

                    // state.cartList.push(state.cartList2[j])
                }
            }
        }
        state.cartList = state.cartList.concat(arr)
        state.cartList2.splice(0)
    }
}
export default mutations